package com.wawayaya.bookreader;

import android.graphics.Color;

/**
 * book reader 配置信息
 */
public class DefaultSettings {

	/**缓存时间，1天，单位毫秒*/
	public final static long CACHE_DELTA_ONE_DAY = 86400*1000;
	/**封面缓存时间*/
	public final static long CACHE_DELTA_COVER = CACHE_DELTA_ONE_DAY * 360 * 70;

	private DefaultSettings(){
	}

	private final static int STANDARD_WIDTH = 360;	// for density is 1  //720 is for density is 2  
	private final static int STANDARD_HEIGHT = 640; // for density is 1  //1280 is for density is 
	public final static int getstandardWidth(boolean blandscape){
		return blandscape ? STANDARD_HEIGHT : STANDARD_WIDTH;
	}
	public final static int getstandardHeight(boolean blandscape){
		return blandscape ? STANDARD_WIDTH : STANDARD_HEIGHT;		
	}

	public final static int BOOKTOPMENUBAR_TITLEFONT_SIZE = 22; 
	public final static int BOOKTOPMENUBAR_TITLEFONT_MAXSIZE = 30; 
	public final static int BOOKTOPMENUBAR_TITLEFONT_COLOR = Color.WHITE; // Color.BLACK;
	public final static int BOOKTOPMENUBAR_TOBOOKSHELFSIZE = 30; 
	public final static int BOOKTOPMENUBAR_MAXOBOOKSHELFSIZE = 48; 
	
	public final static int BOOKTOPMENUBAR_BOOKSETTINGSSIZE = 36; 
	public final static int BOOKTOPMENUBAR_MAXBOOKSETTINGSSIZE = 64; 
	public final static int BOOKTOPMENUBAR_BOOKSETTINGSMARGIN = 8; 
	
	public final static int BOOKTOPMENUBAR_POPMENURIGHTMARGIN = 8;
	public final static int BOOKTOPMENUBAR_POPMENU_ENGLISHSIZE = 30;
	public final static int BOOKTOPMENUBAR_POPMENU_PINYINSIZE = 30;
	public final static int BOOKTOPMENUBAR_POPMENU_AUTOKOKSIZE = 30;
	public final static int BOOKTOPMENUBAR_POPMENU_INTERNALV_MARGIN = 0;
	public final static int BOOKTOPMENUBAR_POPMENU_INTERNALH_MARGIN = 4; 
 
	
	public final static int PAGESELECTION_REGION_BUTTOMMARGIN = 2;
	private final static int PAGESELECTION_REGION_WIDTH = 330;
	public  final static int getselectionRegionWidth(boolean blandscape) {
		//return blandscape ? STANDARD_HEIGHT * PAGESELECTION_REGION_WIDTH / STANDARD_WIDTH : PAGESELECTION_REGION_WIDTH;
		return blandscape ? (STANDARD_HEIGHT - (STANDARD_WIDTH - PAGESELECTION_REGION_WIDTH)) : PAGESELECTION_REGION_WIDTH;
	}
	public final static int PAGESELECTION_REGION_HEIGHT = 30;
	private final static int PAGESELECTION_SEKKBAR_WIDTH = 280;
	public  final static int getseekbarWidth(boolean blandscape) {
		return blandscape ? STANDARD_HEIGHT * PAGESELECTION_SEKKBAR_WIDTH / STANDARD_WIDTH : PAGESELECTION_SEKKBAR_WIDTH;
	}
	public final static int PAGESELECTION_FOOTFONT_SIZE = 18;  
	public final static int PAGESELECTION_FOOTFONT_MAXSIZE = 28;  //
	public final static int PAGESELECTION_FOOTFONT_CURPAGE_COLOR = Color.WHITE; // 0xff212121;
	public final static int PAGESELECTION_FOOTFONT_CUT_COLOR = Color.WHITE; // 0xff212121;
	public final static int PAGESELECTION_FOOTFONT_TOTALPAGE_COLOR = Color.WHITE; // 0xff9e9e9e;
	public final static int PAGESELECTION_FOOTFONT_TOTALPAGE_COLORSHORT = 0xff9e9e9e;

	public final static int WORDDICTDESC_WAIT_WIDTH = 260;
	public final static int WORDDICTDESC_WAIT_HEIGHT = 160;
	public final static int WORDDICTDESC_WAIT_PROGRESSSIZE = 30;
	public final static int WORDDICTDESC_WAIT_CONTENTCOLOR = 0xff42bd41;
	public final static int WORDDICTDESC_WAIT_CONTENTTOPMARGIN = 10;
	public final static int WORDDICTDESC_WAIT_CONTENTFONT = 14;

	public final static int WORDDICTDESC_H_WORKREGION_HEADDCORATION_WIDTH = 318;
	public final static int WORDDICTDESC_H_WORKREGION_HEADDCORATION_HEIGHT = 74;
	public final static int WORDDICTDESC_WORKREGION_HEADDCORATION_WIDTH = 318;
	public final static int WORDDICTDESC_WORKREGION_HEADDCORATION_HEIGHT = 100;
	private final static int WORDDICTDESC_WORKREGION_MAXWIDTH_VERTICALBOOK = 480;
	private final static int WORDDICTDESC_WORKREGION_MAXHEIGHT_VERTICALBOOK = 720;
	private final static int WORDDICTDESC_WORKREGION_MAXWIDTH_LANDSCAPEBOOK = 480;
	private final static int WORDDICTDESC_WORKREGION_MAXHEIGHT_LANDSCAPEBOOK = 620;
	private final static int WORDDICTDESC_WORKREGION_MAXWIDTH_VERTICALBOOK_2 = 640;
	private final static int WORDDICTDESC_WORKREGION_MAXHEIGHT_VERTICALBOOK_2 = 800;
	private final static int WORDDICTDESC_WORKREGION_MAXWIDTH_LANDSCAPEBOOK_2 = 720;
	private final static int WORDDICTDESC_WORKREGION_MAXHEIGHT_LANDSCAPEBOOK_2 = 640;
	private final static int WORDDICTDESC_WORKREGION_MAXWIDTH_VERTICALBOOK_3 = 800;
	private final static int WORDDICTDESC_WORKREGION_MAXHEIGHT_VERTICALBOOK_3 = 1280;
	private final static int WORDDICTDESC_WORKREGION_MAXWIDTH_LANDSCAPEBOOK_3 = 1280;
	private final static int WORDDICTDESC_WORKREGION_MAXHEIGHT_LANDSCAPEBOOK_3 = 880;
	protected final static int WORDDICTDESC_WORKREGION_MINMARGINX = 20;
	protected final static int WORDDICTDESC_WORKREGION_MINMARGINY = 20;
	protected final static int WORDDICTDESC_WORKREGION_UNWORKEDREGION_LANDSCAPE = 60;
	protected final static int WORDDICTDESC_WORKREGION_UNWORKEDREGION_VETICAL = 220;
	public final static int Get_WORDDICTDESC_WORKREGION_MAXWIDTH(boolean bislandscape, float fscreendensity) {
		if(fscreendensity - 2.9f > 0.05f){
			return bislandscape ? WORDDICTDESC_WORKREGION_MAXWIDTH_LANDSCAPEBOOK_3 : WORDDICTDESC_WORKREGION_MAXWIDTH_VERTICALBOOK_3;
		}
		if(fscreendensity - 1.9f > 0.05f){
			return bislandscape ? WORDDICTDESC_WORKREGION_MAXWIDTH_LANDSCAPEBOOK_2 : WORDDICTDESC_WORKREGION_MAXWIDTH_VERTICALBOOK_2;
		}
		return bislandscape ? WORDDICTDESC_WORKREGION_MAXWIDTH_LANDSCAPEBOOK : WORDDICTDESC_WORKREGION_MAXWIDTH_VERTICALBOOK;
	}
	public final static int Get_WORDDICTDESC_WORKREGION_MAXHEIGHT(boolean bislandscape, float fscreendensity) {
		if(fscreendensity - 2.9f > 0.05f){
			return bislandscape ? WORDDICTDESC_WORKREGION_MAXHEIGHT_LANDSCAPEBOOK_3 : WORDDICTDESC_WORKREGION_MAXHEIGHT_VERTICALBOOK_3;
		}
		if(fscreendensity - 1.9f > 0.05f){
			return bislandscape ? WORDDICTDESC_WORKREGION_MAXHEIGHT_LANDSCAPEBOOK_2 : WORDDICTDESC_WORKREGION_MAXHEIGHT_VERTICALBOOK_2;
		}
		return bislandscape ? WORDDICTDESC_WORKREGION_MAXHEIGHT_LANDSCAPEBOOK : WORDDICTDESC_WORKREGION_MAXHEIGHT_VERTICALBOOK;
	}

	private final static int DOQUIZ_WOWIMAGE_TOPMARGIN = 120;
	public final static int getquizwowimageTopmargin(boolean blandscape){
		return blandscape ? DOQUIZ_WOWIMAGE_TOPMARGIN * STANDARD_WIDTH / STANDARD_HEIGHT : DOQUIZ_WOWIMAGE_TOPMARGIN;
	}
	private final static int DOQUIZ_DOQUIZFAILED_WIDTH = 300;
	public final static int getquizfailedWidth(boolean blandscape){
		return blandscape ? DOQUIZ_DOQUIZFAILED_WIDTH * STANDARD_HEIGHT / STANDARD_WIDTH : DOQUIZ_DOQUIZFAILED_WIDTH;
	}
	public final static int DOQUIZ_DOQUIZFAILED_HEIGHT = 60;
	private final static int DOQUIZ_DOQUIZFAILED_TOPMARGIN = 270;
	public final static int getquizfailedTopmargin(boolean blandscape){
		return blandscape ? DOQUIZ_DOQUIZFAILED_TOPMARGIN * STANDARD_WIDTH / STANDARD_HEIGHT : DOQUIZ_DOQUIZFAILED_TOPMARGIN;
	}
	private final static int DOQUIZ_QUIZFAILEDANIM_TOPPOS = 330;
	public final static int getquizfailedToppos(boolean blandscape){
		return blandscape ? DOQUIZ_QUIZFAILEDANIM_TOPPOS * STANDARD_WIDTH / STANDARD_HEIGHT : DOQUIZ_QUIZFAILEDANIM_TOPPOS;
	}
	private final static int DOQUIZ_QUIZFAILEDANIM_ENDPOS = 350;
	public final static int getquizfailedanimEndpos(boolean blandscape){
		return blandscape ? DOQUIZ_QUIZFAILEDANIM_ENDPOS * STANDARD_WIDTH / STANDARD_HEIGHT : DOQUIZ_QUIZFAILEDANIM_ENDPOS;
	}
	public final static int DOQUIZ_DOQUIZBUTTON_WIDTH = 330;
	public final static int DOQUIZ_DOQUIZBUTTON_HEIGHT = 60;
	private final static int DOQUIZ_DOQUIZBUTTON_TOPMARGIN = 420;
	public final static int getquizbuttonEndpos(boolean blandscape){
		return blandscape ? DOQUIZ_DOQUIZBUTTON_TOPMARGIN * STANDARD_WIDTH / STANDARD_HEIGHT : DOQUIZ_DOQUIZBUTTON_TOPMARGIN;
	}

	public final static int DETAIL_H_BUTTON_READMYSELF_LEFTMARGIN = 77; 
	public final static int DETAIL_H_BUTTON_READMYSELF_TOPMARGIN = 90; 
	public final static int DETAIL_H_BUTTON_READTOMY_LEFTMARGIN = 132; 
	public final static int DETAIL_H_BUTTON_READTOMY_TOPMARGIN = 220;
	public final static int DETAIL_H_BUTTON_TELL_RIGHTMARGIN = DETAIL_H_BUTTON_READMYSELF_LEFTMARGIN;
	public final static int DETAIL_H_BUTTON_TELL_TOPMARGIN = DETAIL_H_BUTTON_READMYSELF_TOPMARGIN;
	public final static int DETAIL_H_BUTTON_WATCH_RIGHTMARGIN = DETAIL_H_BUTTON_READTOMY_LEFTMARGIN;
	public final static int DETAIL_H_BUTTON_WATCH_TOPMARGIN = DETAIL_H_BUTTON_READTOMY_TOPMARGIN;

	public final static int MORELIST_RACKNAME_FONTSIZE = 16;
	public final static int MORELIST_RACKNAME_MAXFONTSIZE = 22;

	// 1. book_page; 2. book_content; 3. forecover; 4. backcover; 5. book-self quiz page
	public final static int ms_Json_BookPageType_unknown = 0;
	public final static int ms_Json_BookPageType_page = 1;  // formal book page
	public final static int ms_Json_BookPageType_catalog = 2;  // catalog page
	public final static int ms_Json_BookPageType_cover = 3;  // cover page
	public final static int ms_Json_BookPageType_backover = 4;  // backcover page
	public final static int ms_Json_BookPageType_supplement = 5;  // supplement
	public final static int ms_Json_BookPageType_bookquiz = 6;  // book-self quiz page

	public final static int ms_Json_ImgCombineType_unknown = 0;
	public final static int ms_Json_ImgCombineType_WholeImages = 1;  //   "wg"
	public final static int ms_Json_BookPageType_SeparateImages = 2;  //  "bg" & "fg" -- "cn"{},"en"{},"py"{}
	public final static int ms_Json_BookPageType_FractionImages = 3;  //  "bg" & "fg" -- "cn"[],"en"[],"py"[]
	public final static String ms_Json_CombinedImageSuffix = ".cj";

	public static final  int SPEED_NORMAL = 0;
	public static final  int SPEED_FAST = 1;
	public static final  int SPEED_SLOW = 2;

	public final static int BOOKREADTYPE_READMYSELF = 1;
	public final static int BOOKREADTYPE_READTOME = 2;
	public final static int BOTTOMMARGIN = 40;
	public final static int FONTSIZE = 4;

	public final static int BOOK_ORIENTATION_LANDSCAPE = 0;
	public final static int BOOK_ORIENTATION_PORTRAIT = 1;

	public final static String BUNDLE_BOOKNETID = "netid";
	public final static String BUNDLE_BOOKID = "bookid";
	public final static String BUNDLE_BOOKNAME = "bookname";
	public final static String BUNDLE_TOTALPAGE = "totalpage";
	public final static String BUNDLE_BOOKPAGE = "bookpage";
	public final static String BUNDLE_CATALOGID = "icatalogId";
	public final static String BUNDLE_ITEMID = "iitemId";
	public final static String BUNDLE_SERIALIZEDPARTPATH = "serializedpartpath";

	public final static int Msg_BOOKPARTREADYFORREAD = 1;
	public final static int Msg_BOOKPARTDOWNLAODERROR = 2;

	public final static int BANNERTITLE_HEIGHT_V = 34;
	public final static int BANNERTITLE_HEIGHT_VMAX = 102;

	public final static int READBOOK_QUITNOBUNDLE = 1;
	public final static int READBOOK_QUITNODATA = 2;
	/**
	 * 获取 屏幕比例
	 * @param iscreenWidth
	 * @param iscreenHeight
	 * @param ibookpageWidth
	 * @param ibookpageHeight
	 * @param iourpageWidth
	 * @param iourpageHeight
	 * @return
	 * @throws Exception
	 */
	public static float getToScreenRatio(int iscreenWidth, int iscreenHeight,
										 int ibookpageWidth, int ibookpageHeight,
										 int iourpageWidth, int iourpageHeight) throws Exception {
		if(iscreenWidth <= 0 || iscreenHeight <= 0 ||
				ibookpageWidth <= 0 || ibookpageHeight <= 0 ||
				iourpageWidth <= 0 || iourpageHeight <= 0) {
			throw new Exception("Parameters Error!");
		}
		if(iourpageWidth * ibookpageHeight != iourpageHeight * ibookpageWidth){
			throw new Exception("Parameters Error!");
		}
		int iowsh = iourpageWidth * iscreenHeight;
		int iohsw = iourpageHeight * iscreenWidth;
		if(iowsh >= iohsw) {
			//	(ow/bw) * (sw/ow) = sw/bw;
			return (float)iscreenWidth / (float)ibookpageWidth;
		}
		else{
			//	(ow/bw) * (sh/oh) = (ow*sh)/(bw*oh);
			return (float)(iourpageWidth * iscreenHeight) / (float)(ibookpageWidth * iourpageHeight);
		}
	}

	/**
	 * 文字 大小
	 * @param ifontsize
	 * @param fratio
	 * @param fscreendensity
	 * @return
	 */
	public static int getscaledfontsize(int ifontsize, float fratio, float fscreendensity) {
		if(Math.abs(fscreendensity - 0.0f) < 0.01f) {
			fscreendensity = 1.0f;
		}
		return (int)((float)ifontsize * fratio + 0.499f);
	}

}
